package com.upstairstechnology.oi;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * "Outstanding Integrations" application start class.
 * 
 * @author Jeff Jensen
 */
public class Oi {
    /** Logger instance. */
    private static final Logger LOGGER = LoggerFactory.getLogger(Oi.class);

    static {
        ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
    }

    /**
     * Initialize Spring Framework.
     * 
     * @return Spring's application context.
     */
    private static ApplicationContext initSpring() {
        LOGGER.debug("Begin configuring Spring Framework");
        String[] springConfigLocations =
                new String[] {"applicationContext.xml"};
        ApplicationContext springContext =
                new ClassPathXmlApplicationContext(springConfigLocations);
        LOGGER.debug("Done configuring Spring Framework");
        return springContext;
    }

    /**
     * Startup method.
     * 
     * @param args
     *            Args to program.
     */
    public static void main(String[] args) {
        try {
            LOGGER.info("Starting oi");
            ApplicationContext springContext = initSpring();
            OiRunner oiRunner =
                    (OiRunner) springContext
                            .getBean("oiRunner", OiRunner.class);
            oiRunner.run();
        } catch (Exception e) {
            LOGGER.error("Exiting with Exception: ", e);
        }
    }
}
